<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>YOLO Video Stream</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f0f0f0;
            margin: 0;
        }
        #video-stream {
            max-width: 100%;
            max-height: 100%;
            border: 2px solid #000;
        }
    </style>
</head>
<body>
    <img id="video-stream" src="" alt="Video Stream">
    <script>
        const ws = new WebSocket("ws://202.114.212.194:50511/detect");

        ws.onopen = () => {
            console.log("WebSocket connection opened");
        };

        ws.onmessage = (event) => {
            console.log("Message received");
            try {
                const data = JSON.parse(event.data);
                console.log("Parsed data:", data);
                const img = document.getElementById("video-stream");
                img.src = "data:image/jpeg;base64," + data.image;
                console.log("Image updated");
            } catch (error) {
                console.error("Error parsing message:", error);
            }
        };

        ws.onerror = (error) => {
            console.error("WebSocket error:", error);
        };

        ws.onclose = () => {
            console.log("WebSocket connection closed");
        };
    </script>
</body>
</html>